package com.vision.sales.sv.serv.rpc;

import com.vision.core.cm.exception.RpcException;
import com.vision.core.sv.serv.rpc.AbstractServiceImpl;
import com.vision.sales.cm.data.IHasTransactionStatus;
import com.vision.sales.cm.data.TransactionStatus;

/**
 * 
 * @author Mark
 *
 */
public abstract class TransactionServiceImpl<T extends IHasTransactionStatus> extends AbstractServiceImpl<T> {

	private static final long serialVersionUID = 1L;
	
	// Helpers %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
	
	protected void checkCanEditByStatus(IHasTransactionStatus transaction, String name) throws RpcException {
		if (transaction.getStatus() != TransactionStatus.PENDING)
			throw new RpcException("The " + name + " is already posted. It cannot be modified.");
	}
	
	protected void checkCanDeleteByStatus(IHasTransactionStatus transaction, String name) throws RpcException {
		if (transaction.getStatus() != TransactionStatus.PENDING)
			throw new RpcException("The " + name + " is already deleted. It cannot be modified.");
	}

}
